package org.hdax.dm.rest.service;

import org.hdax.dm.dao.entitydao.LinkUserDao;
import org.hdax.dm.entity.linkuser.LinkUser;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class RestLinkUserService {
    @Autowired
    private LinkUserDao linkUserDao;

    @PostMapping(path = "/findByUserId")
    public LinkUser findByUserId(@RequestParam("userId") Long userId) {
        return linkUserDao.findByUserId(userId);
    }

    @PostMapping(path = "/addLinkUser")
    public LinkUser addLinkUser(@RequestBody LinkUser linkUser) {
        return linkUserDao.save(linkUser);
    }


    @PostMapping(path = "/findLinkUserById")
    public LinkUser findLinkUserById(@RequestParam("id") Long id) {
        return linkUserDao.findById(id).get();
    }


    @PostMapping(path = "/findByIdCard")
    public LinkUser findByIdCard(@RequestParam("idCard") String idCard) {
        return linkUserDao.findByIdCard(idCard);
    }


    @PostMapping(path = "/deleteLinkUserById")
    public void deleteLinkUserById(@RequestParam("linkId") Integer linkId) {
        linkUserDao.deleteByUserId(linkId);
    }
}
